package de.tum.se.sudoku.gui;

import java.awt.Color;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;

import de.tum.se.sudoku.impl.Grid;
import de.tum.se.sudoku.impl.VariableCell;

public class SudokuBox extends JPanel {
	private static final long serialVersionUID = 1L;

	public SudokuBox(JPanel father, int boxNumber, Grid grid) {
		super();
		setLayout(new GridLayout(3, 3));

		int row = 0;
		int col = 0;

		switch (boxNumber) {
		case 0:
			row = 0;
			col = 0;
			break;
		case 1:
			row = 0;
			col = 3;
			break;
		case 2:
			row = 0;
			col = 6;
			break;
		case 3:
			row = 3;
			col = 0;
			break;
		case 4:
			row = 3;
			col = 3;
			break;
		case 5:
			row = 3;
			col = 6;
			break;
		case 6:
			row = 6;
			col = 0;
			break;
		case 7:
			row = 6;
			col = 3;
			break;
		case 8:
			row = 6;
			col = 6;
			break;
		}

		for (int i = 0; i < 3; ++i)
			for (int j = 0; j < 3; ++j)
				if (grid.getCell(row + i, col + j) instanceof VariableCell)
					add(new SudokuComboBox(row + i, col + j, grid));
				else
					add(new JLabel(""
							+ grid.getCell(row + i, col + j).getValue()));

		setBorder(BorderFactory.createLineBorder(Color.BLACK, 3));

		setVisible(true);
	}

}
